<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta content="telephone=no" name="format-detection" />
    <!-- 留作将来统一添加 -->
    <TEMPLATE>${TEMPLATE}</TEMPLATE>
    <title>班级公告</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css">
    <link rel="stylesheet" type="text/css" href="../../css/index.css">
    <link rel="stylesheet" type="text/css" href="../../css/data-flex.min.css">
    <style type="text/css">
        body {
            background: rgba(245, 245, 245, 1);
        }

        .box {
            background: rgba(255, 255, 255, 1);
            overflow: hidden;
            margin-bottom: 10px
        }

        .row {
            margin: 15px;
        }

        .avatar {
            width: 32px;
            height: 32px;
            border-radius: 50%;
            margin-right: 10px;
        }

        .name {
            font-size: 15px;
            font-weight: 400;
            color: rgba(25, 25, 25, 1);
        }

        .time {
            font-size: 12px;
            font-weight: 400;
            color: rgba(191, 191, 191, 1);
        }

        .content {
            font-size: 14px;
            font-weight: 400;
            color: rgba(128, 128, 128, 1);
            line-height: 20px;
        }

        .image {
            height: 183px;
            border-radius: 8px;
            overflow: hidden;
            margin-top: 5px;
        }

        .btn {
            position: fixed;
            bottom: 0;
            width: 100%;
            height: 50px;
            background: rgba(90, 194, 255, 1);
            font-size: 16px;
            font-weight: 600;
            color: rgba(255, 255, 255, 1);
            line-height: 22px;
        }

        .info {
            width: 173px;
            height: 36px;
            background: rgba(194, 232, 255, 0.66);
            border-radius: 24px;
            margin: 15px auto;
        }

        .info-avatar {
            width: 26px;
            height: 26px;
            margin-right: 8px;
            border-radius: 50%;
        }

        .info-text {
            font-size: 13px;
            font-weight: 400;
            color: rgba(25, 89, 126, 1);
        }

        .btn-occupy {
            height: 50px;
        }
    </style>
</head>

<body>
    <div class="vueApp" v-cloak>
        <!-- <div class="info" v-if="userType == 1 && listData.length > 0" data-flex="main:center cross:center">
            <div class="info-avatar">
                <img :src="listData[0].icon" alt="">
            </div>
            <div class="info-text">
                老师新发布了1条消息
            </div>
        </div> -->
        <div class="box" v-for="item in listData" @click="noticesFn(item)">
            <div class="row" data-flex>
                <div class="avatar">
                    <img :src="item.icon" alt="">
                </div>
                <div data-flex-box="1">
                    <div class="name">{{ item.nickName }}</div>
                    <div class="time">{{ transformDate(item.createDate) }}</div>
                </div>
            </div>
            <div class="row">
                <div class="content" v-if="item.content">
                    {{ item.content }}
                </div>
                <div class="image" v-if="item.url">
                    <img :src="firstImage(item)" alt="">
                </div>
            </div>
        </div>
        <!-- 按钮占位 -->
        <div class="btn-occupy" v-if="userType == 2"></div>
        <div class="btn" v-if="userType == 2" data-flex="main:center cross:center" @click="postFn()">
            发布公告
        </div>
    </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/service/service-tool.js"></script>
<script type="text/javascript" src="../../script/service/service-app.js"></script>
<script type="text/javascript" src="../../script/service/service-user.js"></script>
<script type="text/javascript" src="../../script/service/service-logic.js"></script>
<script type="text/javascript" src="../../script/jquery.min.js"></script>
<script type="text/javascript" src="../../script/vue.min.js"></script>
<script type="text/javascript">
    // html 的引号一律为双引号(""),js 为单引号('')
    var USER, $S, vm, param;
    apiready = function () {
        $S = SERVICE();
        USER = USER();
        console.log(JSON.stringify(api.pageParam) + '=====pageParam');
        // 如果班级公告发生变更
        api.addEventListener({
            name: 'classNoticeChange'
        }, function (ret, err) {
            refreshData();
        });
        // 如果班级公告有删除
        api.addEventListener({
            name: 'classNoticeDelete'
        }, function (ret, err) {
            refreshData();
        });
        param = api.pageParam;
        fnInit();
    };
    // 初始化
    function fnInit() {
        vm = new Vue({
            el: '.vueApp',
            data: {
                userType: getUserType(),
                listData: '',
                pageNo: 1,
                pageSize: 10
            },
            methods: {
                transformDate: function (date) {
                    return formateTime(date, 'order_data');
                },
                firstImage: function (item) {
                    return item.url.split(',')[0]
                }
            }
        });
        load();
    }

    // 点击公告跳转示范
    function noticesFn(item) {
        fnOpenPublicWin(
            '班级公告',
            'class/notice',
            {
                noticeId: item.id
            }
        );
    }

    // 点击发布公告跳转示范
    function postFn() {
        fnOpenPublicWin('发布公告', 'class/post', {
            isBtn: true,
            btnName: '发布',
            headerFn: 'headerFn',
            classesId: param.classesId
        })
    }

    function load() {
        getPageData('headerRefreshing');
        fnAddHeaderRefreshingEvent(function () { //设置下拉刷新
            getPageData('headerRefreshing');
        });

        fnAddFooterLoadingEvent(function () { // 设置上拉加载
            getPageData('load');
        });

    }

    // 获取页面数据
    function getPageData(sign) {
        if (sign == 'headerRefreshing') {
            vm.pageNo = 1;
        } else {
            vm.pageNo++;
        }
        var url = 'clsClass/findNoticeList';
        var params = {
            "classesId": param.classesId,
            'pageNo': vm.pageNo,
            'pageSize': vm.pageSize
        };
        var callback = function (data) {
            if (vm.pageNo == '1') {
                vm.listData = [];
            }
            api.refreshHeaderLoadDone();
            vm.listData = vm.listData.concat(data.listData);
            // status 为200时,只返回data
        };
        POST(url, params, callback);
    }

    // 刷新数据
    function refreshData() {
        var url = 'clsClass/findNoticeList';
        var params = {
            "classesId": param.classesId
        };
        var callback = function (data) {
            vm.listData = data.listData;
            vm.pageNo = 1;
            // status 为200时,只返回data
        };
        POST(url, params, callback);
    }

    function headerFn() {
        fnOpenAlert({
            alertType: '8',
            alertConfirmFn: 'clearClassNotices'
        })
    }

    // 清空班级公告
    function clearClassNotices() {
        var url = 'clsClass/deleteNoticeList';
        var params = {
            "classesId": param.classesId
        };
        var callback = function (data) {
            fnToast('清空成功');
            api.sendEvent({
                name: 'classNoticeDelete'
            })
            // status 为200时,只返回data
        };
        POST(url, params, callback);
    }
</script>

</html>